package ua.kpi_java_training.zabrodskyi.module1;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * Class is designed to test methods of the class DividerInColumn.
 * 
 * @version 1.02 28 May 2013
 * @author Maksym Zabrodskyi
 */
public class DividerInColumnTest {

	@Test
	public void testGetDigitOfDivinend() {
		int dividend = 345;
		DividerInColumn.dividendStr = Integer.toString(dividend);
		String expectedResult = Integer.toString(4);
		int index = 1;
		String actualResult = DividerInColumn.getDigitOfDivinend(index);
		assertEquals(expectedResult, actualResult);
	}

	@Test
	public void testGetDigitOfNegativeDivinend() {
		int dividend = -345;
		DividerInColumn.dividendStr = Integer.toString(Math.abs(dividend));
		String expectedResult = Integer.toString(4);
		int index = 1;
		String actualResult = DividerInColumn.getDigitOfDivinend(index);
		assertEquals(expectedResult, actualResult);
	}

	@Test
	public void testGetWhole() {
		int numerator = 24;
		int divisor = 5;
		int expectedWhole = 20;
		int actualWhole = DividerInColumn.getWhole(numerator, divisor);
		assertEquals(expectedWhole, actualWhole);
	}

	@Test
	public void testIsDivisorNotZero() {
		int divisor = 34;
		assertFalse(DividerInColumn.isDivisorZero(divisor));
		divisor = -25;
		assertFalse(DividerInColumn.isDivisorZero(divisor));
	}

	@Test
	public void testIsDivisorZero() {
		int divisor = 0;
		assertTrue(DividerInColumn.isDivisorZero(divisor));
	}

	@Test
	public void testGetSize() {
		int number = 12684;
		int expectedSize = 5;
		int actualSize = DividerInColumn.getSize(number);
		assertEquals(expectedSize, actualSize);
	}

	@Test
	public void testGetDashInt() {
		int numberDash = 4;
		String expectedDash = String.format("%0" + numberDash + "d", 0)
				.replace("0", "-");
		String actualDash = DividerInColumn.getDash(numberDash);
		assertEquals(expectedDash, actualDash);
	}

	@Test
	public void testGetDashIntInt() {
		int firstNumberDash = 2;
		int secondNumberDash = 3;
		int numberDash = Math.max(firstNumberDash, secondNumberDash);
		String expectedDash = String.format("%0" + numberDash + "d", 0)
				.replace("0", "-");
		String actualDash = DividerInColumn.getDash(firstNumberDash,
				secondNumberDash);
		assertEquals(expectedDash, actualDash);
	}

	@Test
	public void testGetSpacesInt() {
		int numberSpaces = 4;
		String expectedSpaces = "    ";
		String actualSpaces = DividerInColumn.getSpaces(numberSpaces);
		assertEquals(expectedSpaces, actualSpaces);
	}

	@Test
	public void testGetNullSpacesInt() {
		int numberSpaces = 0;
		String expectedSpaces = "";
		String actualSpaces = DividerInColumn.getSpaces(numberSpaces);
		assertEquals(expectedSpaces, actualSpaces);
	}

	@Test
	public void testGetSpacesIntInt() {
		int firstNumberSpaces = 2;
		int secondNumberSpaces = 7;
		int numberSpaces = Math.abs(firstNumberSpaces - secondNumberSpaces);
		String expectedSpaces = String.format("%" + numberSpaces + "s", "");
		String actualSpaces = DividerInColumn.getSpaces(firstNumberSpaces,
				secondNumberSpaces);
		assertEquals(expectedSpaces, actualSpaces);
	}

	@Test
	public void testGetNullSpacesIntInt() {
		int firstNumberSpaces = 4;
		int secondNumberSpaces = 4;
		String expectedSpaces = "";
		String actualSpaces = DividerInColumn.getSpaces(firstNumberSpaces,
				secondNumberSpaces);
		assertEquals(expectedSpaces, actualSpaces);
	}
}

